﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HCY.CTP.DBShangZheng;

namespace IFClientDLL.MyCalc.CalcTrade
{
    public class CalcTrade_StopLoss : CalcTrade_Empty
    {
        public const int DefaultLossBit = -5;
        private int _lossbit;
        public CalcTrade_StopLoss(ITryIF tryif, int lossbit = DefaultLossBit)
            : base(tryif)
        {
            _lossbit = lossbit;
        }
        protected override void CalcTrade(IFServerDLL.Model.TradeOnHand tradeOnhand, MyIF myif)
        {
            var variety = IFServerDLL.Model.MyVariety.GetVarietyByInstrument(tradeOnhand.Instrument);
            if ((tradeOnhand.MarketProfit / tradeOnhand.SumALLVolume / variety.Count / variety.OneChangedPrice) <= _lossbit)
            {
                _tryif.Calc.CalcCmd.CloseTrade(this, myif, tradeOnhand);
                myif.AddCalcMsg(new CalcMsg(this, "Close the trade onhand " + tradeOnhand.Instrument + " " + tradeOnhand.BuyOrSell.ToString()));
            }
            else
            {
                myif.AddCalcMsg(new CalcMsg(this, " do not need close."));
            }
        }


        public override string CalcName
        {
            get { return "Trade Stop Loss " + _lossbit; }
        }

    }
}
